//
//  SettingsView.m
//  Comma
//
//  Created by dlios on 15-1-13.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "SettingsView.h"
#import "GlobalMacro.h"
#import "GlobalMethod.h"
#import "SDImageCache.h"
@implementation SettingsView

- (void)createMySettings
{
    [self setBackgroundColor:[UIColor whiteColor]];
//    [self createLeftButton];
    [self clearDisk];
    [self logout];
}

- (void)creatLeftButtonWithTitle:(NSString *)leftTitle
{
    self.leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.leftButton setFrame:CGRectMake(0, 20, 48, 44)];
    [self.leftButton setBackgroundImage:[UIImage imageNamed:@"Button_drawer(1)"] forState:UIControlStateNormal];
    [self.leftButton addTarget:self action:@selector(leftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.headerView addSubview:self.leftButton];

}
- (void)clearDiskSeperateLine
{
    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, 152) EndPoint:CGPointMake(SCREEN_WIDTH, 152) inUIView:self];
}

- (void)changeMyPassword
{
    self.changeButton = [[UIButton alloc] initWithFrame:CGRectMake(16, 108, SCREEN_WIDTH - 16, 88)];
    [self.changeButton setBackgroundColor:[UIColor clearColor]];
    [self addSubview:self.changeButton];
    
    self.changePassword = [[UIButton alloc] initWithFrame:CGRectMake(0, 12, 60, 20)];
    [self.changePassword setBackgroundColor:[UIColor clearColor]];
    [self.changePassword setTitle:@"修改密码" forState:UIControlStateNormal];
    self.changePassword.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.changePassword setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
    [self.changeButton addSubview:self.changePassword];
    
    UIImageView *toRight = [[UIImageView alloc] initWithFrame:CGRectMake(336, 14, 15, 15)];
    [toRight setImage:[UIImage imageNamed:@"Button_updown_open"]];
    
    //把 向上的箭头向右旋转90度  然后缩放到原来大得0.6倍
    toRight.transform = CGAffineTransformMakeRotation(M_PI_2);
    CGAffineTransform transform = toRight.transform;
    transform = CGAffineTransformScale(transform, 0.6, 0.6);
    toRight.transform = transform;

 
    [self.changeButton addSubview:toRight];
    
    
}
#pragma mark - 清除缓存
- (void)clearDisk
{
    self.clearBackButton = [[UIButton alloc] initWithFrame:CGRectMake(16, 108, SCREEN_WIDTH - 16, 44)];
    [self.clearBackButton setBackgroundColor:[UIColor clearColor]];
    [self addSubview:self.clearBackButton];
    
    
    self.clearButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 12, 60, 20)];
    [self.clearButton setBackgroundColor:[UIColor clearColor]];
    [self.clearButton setTitle:@"清空缓存" forState:UIControlStateNormal];
    [self.clearButton setTitleColor:TEXTGREENCOLOR forState:UIControlStateNormal];
    self.clearButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.clearBackButton addSubview:self.clearButton];
    
    self.memorySize = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 86, 12, 50, 20)];
    [self.memorySize setBackgroundColor:[UIColor clearColor]];
#pragma mark - 计算缓存大小
//    创建对象
    self.sdImage = [[SDImageCache alloc] init];
    float clean = [self.sdImage checkTmpSize];
    NSString *myMemory = [NSString stringWithFormat:@"%.2f M", clean];
    [self.memorySize setText:myMemory];
    [self.memorySize setFont:[UIFont systemFontOfSize:14]];
    [self.memorySize setTextColor:TEXTGREENCOLOR];
    [self.memorySize setTextAlignment:NSTextAlignmentRight];
    [self.clearBackButton addSubview:self.memorySize];

  //  [self clearDiskSeperateLine];
    [self clearDiskSeperateLine];

}
//- (void)clearDiskSeperateLine
//{
//    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, 196) EndPoint:CGPointMake(SCREEN_WIDTH, 196) inUIView:self];
//}
- (void)logout
{
    UIView *logoutView = [[UIView alloc] initWithFrame:CGRectMake(16, 284, SCREEN_WIDTH - 16, 132)];
    [logoutView setBackgroundColor:[UIColor clearColor]];
    [self addSubview:logoutView];

    self.logoutButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 80, SCREEN_WIDTH - 32, 70)];
    [self.logoutButton setBackgroundColor:[UIColor clearColor]];
    [self.logoutButton setTitle:@"注销登录" forState:UIControlStateNormal];
    [self.logoutButton setTitleColor:REDCOLOR forState:UIControlStateNormal];
    self.logoutButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [logoutView addSubview:self.logoutButton];
    
    [self logoutSeperateLine];
}
- (void)logoutSeperateLine
{
    [GlobalMethod drawLineWithStartPoint:CGPointMake(0, 416) EndPoint:CGPointMake(SCREEN_WIDTH, 416) inUIView:self];
}

#pragma mark - uiswitch测试
- (void)switchOn:(id)sender
{
    UISwitch *mySwitch = (UISwitch *)sender;
    if (mySwitch.on == YES) {
        [self setBackgroundColor:[UIColor grayColor]];
    }
    else
    {
        [self setBackgroundColor:[UIColor whiteColor]];
    }
    
}

@end
